package com.example.dao;

import com.alibaba.druid.pool.DruidDataSourceFactory;
import com.mysql.cj.jdbc.integration.c3p0.MysqlConnectionTester;

import javax.sql.DataSource;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.util.Properties;

public class DataSourcePool {
    public static Connection getConnection() {
        Connection conn = null;
        InputStream is = MysqlConnectionTester.class.getClassLoader().getResourceAsStream("jdbc.properties");
        Properties info = new Properties();
        try {
            info.load(is);
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            DataSource dataSource = DruidDataSourceFactory.createDataSource(info);
            conn = dataSource.getConnection();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return conn;
    }
}
